#pragma once
#include <sys/epoll.h>
#include <coroutine>
namespace nco
{
    class Epoll;

    class EpollScheduler
    {
    public:
        void operator()();

    private:
        friend Epoll;
        static void add_Co(Epoll *e);
    };

    enum EpollEvent
    {
        eEpollIn = EPOLLIN,
        eEpollOut = EPOLLOUT,
    };
    class Epoll
    {
    public:
        Epoll(EpollEvent e, int fd, int64_t timeout = 0);
        bool await_ready() const;
        void await_resume();
        void await_suspend(std::coroutine_handle<> handle);
        int64_t getTimeout();
        void setTimeout(int64_t t);
        int getFd();
        EpollEvent getEnv();
        bool isTimeout();
        void setIsTimeout(bool b);

    private:
        friend EpollScheduler;
        bool m_isTimeout = true;
        EpollEvent m_eve;
        int m_fd;
        int64_t m_timeout;
        std::coroutine_handle<> m_handle;
    };

}